<?php
if(@$_REQUEST['debug'] == false){
	error_reporting('E_ERROR');	
}

	include_once "../inc_function.php";
	include_once '../../../function/class_tabel_paging.php';

	session_start();
	$current_page = 1;
	if(isset($_GET['page'])){
		$current_page = $_GET['page'];
	}
	$page_per_row1 = 10;
	$start_myrow = ($current_page-1) * $page_per_row1 + 1;
	$end_row = $current_page * $page_per_row1;
	
	$sql_count = "SELECT COUNT(*) AS num_rows FROM VIEW_ANNOUNCEMENT where announcement_id > 0 order by announcement_id asc";
	$headerValue = array(
		'OTHER' => array(
			'ID' => 'ANNOUNCEMENT_ID',
			'DELETE' => array(
				'ID' => 'ANNOUNCEMENT_ID',
				'ACTION' => "ONCLICK = 'deleteRow(%ID%);'"	
			)
		),				
		'TABLE' => array(
			'ANNOUNCEMENT ID' => 'ANNOUNCEMENT_ID',
			'DESCRIPTION' => 'ANNOUNCEMENT_DESC',
			'START DATE' => 'START_DATE',
			'END DATE' => 'END_DATE',
			'COMPANY CODE' => 'COMPANY_CODE'
		 )		
	);
	
	$search = (isset($_REQUEST['search'])) ?$_REQUEST['search']:''; 
	
	$sql1 = array(
		'sql_result' => "BEGIN PKG_ANNOUNCEMENT.SP_GET_ANNOUNCEMENT_BY_NAME(:str_login_name,:int_start_row,:int_end_row,:cursor);END;",
		'condition' => array(
			':int_start_row' => $start_myrow,
			':int_end_row' => $end_row,
			':str_login_name' => $search,
			':cursor' => ''	
		)
	);
	$form = AJAX_PATH."announcement/form.php";
	$paging = new tabel_paging($con,$sql_count,$page_per_row1,$sql1,$headerValue);
    $total_rows = $paging->count_rows($con,$sql_count);
    $total_mypages = $paging->total_pages($total_rows, $page_per_row1);    
?>
<script>
   function cekValue(id,c_name){
      window.parent.window.get_employee(id,c_name);
      self.parent.tb_remove();
   }
   
   function deleteRow(pid,con){
	   var my_confirm = confirm('Do you want to delete this announcement?');
	   if(my_confirm){
		   $.ajax({
			url : "<?= AJAX_PATH;?>announcement/ajax.php",
			type : "POST",
			data : "id="+pid,
			success : function(data){
				if(data){
					$("#row_"+pid).fadeOut('slow',function(){
						$("#row_"+pid).remove();
					});
				}else{
					alert('Error Delete Announcement, Please contant your administrator!!!');
				}
				
			}
		});	
	   }
		
   }
</script>
<body>

<fieldset class="list_login">
   <legend> Dashboard List Login</legend>
   <form action method='get' id=form_search>
	<div>Search : <input type='text' name='search' class='text_search' placeholder='search...' /></div>
	</form>
   <?php echo $paging->paged_result($con,$start_myrow,$page_per_row1,$sql1,$headerValue,$form); ?>
<div class="left">
<a href="<?= $form;?>" class="button left"> Create New </a>
<span class="right"><?php  echo $paging->draw_pager(AJAX_PATH."list_login.php", $total_mypages, $current_page);?></span>
</div>   
</fieldset>
</body>	